﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using PMSGSC.BLL;
using PMSGSC.DAL;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;
namespace PMSGSC.App
{
    public partial class rpPrintStockIn : DevExpress.XtraReports.UI.XtraReport
    {
        Invoice Invoice;
        public rpPrintStockIn(int InvoiceID)
        {
            InitializeComponent();
            bindingSource1.DataSource = Invoice_BLL.GetDataById(InvoiceID);
            Invoice = bindingSource1.Cast<Invoice>().ToList()[0];
            OpenDocument();
        }
        private void OpenDocument()
        {
            string Address = Application.StartupPath + "\\Attachment\\";
            Directory.CreateDirectory(Address);
            if (null != Invoice)
            {
                string fileName = Invoice.Ship.NameShip + Invoice.Ship.Extension;
                Address += fileName;
                xrPictureBox1.ImageUrl = Address;
            }
        }
        public bool ByteArrayToFile(string fileName, byte[] byteArray)
        {
            try
            {
                // Open file for reading
                System.IO.FileStream fileStream = new System.IO.FileStream
                    (fileName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                // Writes a block of bytes
                fileStream.Write(byteArray, 0, byteArray.Length);

                // Close file stream
                fileStream.Close();

                return true;
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.ToString());
            }
            return false;
        }
    }
}
